package com.hqd.ch03.v51.boot.origin;

/**
 * 用于批量查找来源信息
 *
 * @param <K>
 */
@FunctionalInterface
public interface OriginLookup<K> {

    @SuppressWarnings("unchecked")
    static <K> Origin getOrigin(Object source, K key) {
        if (!(source instanceof OriginLookup)) {
            return null;
        }
        try {
            return ((OriginLookup<K>) source).getOrigin(key);
        } catch (Throwable ex) {
            return null;
        }
    }

    /**
     * 获取配置源
     *
     * @param key
     * @return
     */
    Origin getOrigin(K key);

    /**
     * 不变的
     *
     * @return
     */
    default boolean isImmutable() {
        return false;
    }

    default String getPrefix() {
        return null;
    }
}
